package cheme.ProcessEditor.Parts.SolvabilityStatus;
//package cheme.ProcessEditor.Parts.Streams.Tag;

import java.beans.PropertyChangeEvent;

import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.GraphicalEditPart;

import cheme.ProcessEditor.Figures.SolvabilityStatusFig;
import cheme.ProcessEditor.Parts.INonResizablePart;
import cheme.ProcessEditor.Parts.PropertyAwarePart;
import cheme.ProcessEditor.Parts.Equations.PolicyEquationsLayout;
import cheme.ProcessModel.SolvabilityStatus;

 

public class PartSolvabilityStatus extends PropertyAwarePart implements INonResizablePart
{
	public static SolvabilityStatusFig fig;
	
	@Override
	protected SolvabilityStatusFig createFigure() {
				
		fig = new SolvabilityStatusFig(getModel().getMessage());
				
		return fig;
		
	}
	
	@Override
	public SolvabilityStatusFig getFigure() {
		return (SolvabilityStatusFig)super.getFigure();
	}
	
	@Override
	public SolvabilityStatus getModel() {
		return (SolvabilityStatus)super.getModel();
	}

	@Override
	protected void createEditPolicies() {
		installEditPolicy(EditPolicy.LAYOUT_ROLE, new PolicyEquationsLayout());
	}
	
	@Override
	protected void handleBoundsChange(PropertyChangeEvent evt)
	{
		refreshVisuals();
		super.handleBoundsChange(evt);
	}
	
	//PA Change to call Fig's methods
	protected void handleTextChange(PropertyChangeEvent evt)
	{
		SolvabilityStatusFig fig = (SolvabilityStatusFig)super.getFigure();
		String message = getModel().getMessage();
		fig.setMessage(message);
	}
	
	protected void handleColorChange(PropertyChangeEvent evt)
	{
		SolvabilityStatusFig fig = (SolvabilityStatusFig)super.getFigure();
		String color = getModel().getColor();
		if (color.equals("red")){
			fig.setLightRed();
		}
		else{
			fig.setLightGreen();
		}
		
	}
	/**
	 * Reset the layout constraint, and revalidate the content pane
	 */
	protected void refreshVisuals()
	{
		Point loc = getModel().getLocation();
		Rectangle constraint = new Rectangle(loc.x, loc.y, -1, -1);
		
		
	    ((GraphicalEditPart)getParent()).setLayoutConstraint(this, getFigure(), constraint);
		
	}
	
	public static SolvabilityStatusFig getSolvabilityStatusFig()
	{
		return fig;
	}
}
